export class Cookies {
    static TOKEN_KEY: string = 'access_token';

    // 获取cookie
    static getCookie(key: string): string {
        const name = key + "=";
        const ca = document.cookie.split(';');
        for (let i = 0; i < ca.length; i++) {
            const c = ca[i].trim();
            if (c.indexOf(name) === 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }


    // 设置cookie,默认是30天
    static setCookie(key: string, value: string): void {
        const d = new Date();
        d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
        const expires = "expires=" + d.toUTCString();
        document.cookie = key + "=" + value + "; " + expires;
    }
}